package com.bjc.base.web;

import com.bjc.base.bean.ResultVO;
import com.bjc.base.core.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.bjc.base.service.ITaskService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.bjc.base.bean.request.TaskReqVO;
import com.bjc.base.bean.response.TaskVO;

/**
 * <p>
 * 小鱼币任务 前端控制器
 * </p>
 *
 * @author 许自辉
 * @since 2018-06-10
 */
@RestController
@RequestMapping("api/book")
@Api(value = "task-api", tags = { "小鱼币任务相关接口" })
public class TaskController {

    @Autowired
    private ITaskService taskService;

	@ApiOperation("分页查询小鱼币任务")
	@GetMapping("task/findPage")
	public ResultVO getTaskPage(@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize,
			TaskReqVO taskReqVO) {
		PageHelper.startPage(pageNum, pageSize);
		List<TaskVO> taskVOs = taskService.getList(taskReqVO);
		return ResultGenerator.getSuccess(new PageInfo<TaskVO>(taskVOs));
	}
	
	@ApiOperation("分页查询小鱼币任务")
	@GetMapping("task/find")
	public ResultVO getTaske(TaskReqVO taskReqVO) {
		TaskVO taskVO = taskService.get(taskReqVO);
		return ResultGenerator.getSuccess(taskVO);
	}

	@ApiOperation("添加小鱼币任务")
	@PostMapping("task/create")
	public ResultVO createTask(@RequestBody TaskReqVO taskReqVOs) {
		int count = taskService.insert(taskReqVOs);
		return ResultGenerator.getInsertSuccess(count);
	}

	@ApiOperation("更新小鱼币任务")
	@PutMapping("task/update")
	public ResultVO updateTask(@RequestBody TaskReqVO taskReqVOs) {
		int count = taskService.update(taskReqVOs);
		return ResultGenerator.getUpdateSuccess(count);
	}

	@ApiOperation("批量删除小鱼币任务")
	@DeleteMapping("task/deleteList")
	public ResultVO deleteTask(@ApiParam(value = "task id集合") @RequestBody int[] ids) {
		int count = taskService.deleteList(ids);
		return ResultGenerator.getDeleteSuccess(count);
	}

}
